/**
 * Created by Administrator on 2019/5/21/021.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"

class CZML_CummunicationArc {
  constructor(viewer, id, idOther, OrbitVisible, OrbitStartTime, OrbitEndTime) {
    this._viewer = viewer
    this.id = id
    this.idOther = idOther
    this.OrbitVisible = OrbitVisible
    this.OrbitStartTime = OrbitStartTime
    this.OrbitEndTime = OrbitEndTime

    this.CZML_AddCummunicationArc()
  }

  CZML_AddCummunicationArc() {
    // 查找对应id
    const id = this.id
    const idOther = this.idOther
    const FindNode = CZML_GENERALTOOLS_CLASS.CzmlList.find(function (node) {
      return node.data().id === id
    })
    if (FindNode == null) {
      return false
    }
    // 对idOther中有效的id进行查询，如果不在直接退出
    for (let i = 0; i < idOther.length; i++) {
      if (idOther[i] != null) {
        const FindNode = CZML_GENERALTOOLS_CLASS.CzmlList.find(function (node) {
          return node.data().id === idOther[i]
        })
        if (FindNode == null) {
          return false
        }
      }
    }
    // 查询该id相关的所有显示弧度（显示弧度的id命名为：id(航天器id)-to-show+num(递增的number))）
    CZML_GENERALTOOLS_CLASS.DeleteCesiumObjectsByMaskStr(id + "-to-show")
    // 对idOther进行循环
    const CurPathwidth = this.id + "#path.width"
    const CurPosition = this.id + "#position"
    for (let i = 0; i < idOther.length; i++) {
      // 时间转换
      const AvailabilityTime =
        CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitStartTime[i]) +
        "/" +
        CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.OrbitEndTime[i])
      // 添加对象
      const ShowOrbitData = {
        id: id + "-to-show" + idOther[i],
        availability: AvailabilityTime,
        path: {
          show: [
            {
              interval: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
              boolean: this.OrbitVisible
            }
          ],
          width: { reference: CurPathwidth },
          material: FindNode.data().path.material,
          resolution: 120
        },
        position: { reference: CurPosition }
      }
      // 设置非空白弧度颜色
      if (idOther[i] != null) {
        if (ShowOrbitData.path.material.solidColor === undefined) {
          ShowOrbitData.path.material = {
            polylineDash: {
              color: {
                reference: idOther[i] + "#label.fillColor"
              }
            }
          }
        } else {
          // 实线
          ShowOrbitData.path.material = {
            solidColor: {
              color: {
                reference: idOther[i] + "#label.fillColor"
              }
            }
          }
        }
      } else {
        // 空白弧段将id设置为id + "-to-show-blank" + (i + 1)
        ShowOrbitData.id = id + "-to-show-blank" + (i + 1)
      }
      CZML_GENERALTOOLS_CLASS.CzmlList.push(ShowOrbitData)
    }
    // 上图
    CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
    return true
  }
}

export default CZML_CummunicationArc
